<?php

namespace App\Remote\AMap;

use App\Enums\BaseErrorCode;
use App\Exceptions\Custom\ResponseHttpException;
use App\Remote\Remote;

class AMapBaseRemote extends Remote
{

    public static function buildBasicHeaders(): array
    {

      $cookie = "cna=a7oQGnsnJhsCAToio6aVlX+s; xlly_s=1; x5sec=7b227761676272696467652d616c69626162612d616d61703b32223a223462626631333836323237343033343934356330633864613062363237316566434a4336784a6f4745504c756e4a696f7835334d57796941416a44546c2b653942454144227d; tfstk=c1KGBsqhn6NW1JmvOCss08yID3hdZqEVZn8yYAF3KgrlBMKFiEUUzhisKtEXRr1..; l=eBE6sbkcTsvydIA8BO5ZPurza77tUIRbzsPzaNbMiInca691THkfuNCUhWB67dtjgtfAFetyIOiMyRFM-8ULStsLLXHap2zWm6J6-; isg=BExMGCgrQ86_DVcsO2a3PAjQHax-hfAvVGsMEKYNjveLMe47zpT0v_BH0TkJeSiH";
      return [
            "cookie"       => $cookie,
            "content-type" => "application/x-www-form-urlencoded; charset=UTF-8"
        ]; // TODO: Change the autogenerated stub
    }

    static function getBaseUri(): string
    {
        // TODO: Implement getBaseUri() method.
        return "https://lbs.amap.com";
    }


    public static function registerResponseHandle(): \Closure
    {
        return function (string $data) {
            $response = json_decode($data, true);
            if ($response && $response["status"] === "1") {
                return $response;
            } else {
                throw new ResponseHttpException(
                    BaseErrorCode::$ERROR_REMOTE_RMS_RESPONSE,
                    null,
                    "amap [ {$response["info"]} ]"
                );
            }
        };
        // TODO: Change the autogenerated stub
    }
}
